﻿<%@ Page Language="C#" validateRequest="false" AutoEventWireup="true" CodeBehind="ArticleWrite.aspx.cs" Inherits="newBlog.article.ArticleWrite" %>

<%@ Register Src="~/model/allLink.ascx" TagPrefix="uc1" TagName="allLink" %>
<%@ Import Namespace="newBlog.CenterInc.Ctrltor" %>
<%@ Import Namespace="newBlog.CenterInc.model" %>
<%  if (Session["user_id"]==null) {
        Response.Redirect("/index.aspx");
        return;
    }
    string article_id = Request.QueryString["article_id"];
    string edit = Request.QueryString["edit"];
    catalog_inc catalog_Inc = new catalog_inc();
    Article_inc article_Inc = new Article_inc();
    List<Wrting_editDao> editmsg = null;
    int editCount=0;//计算是编辑的文章是否属于本人
    int user_grade = Convert.ToInt32(Session["user_grade"]);
    if (edit!=null&&article_id!=null) {
        editCount = article_Inc.wrting_EditDaosCount(article_id,Session["user_id"].ToString());
        if (editCount!=0||user_grade==1) {
            editmsg = article_Inc.wrting_EditDaos(article_id);
        }
    }
    %>
<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>文章编辑-<%=Application["title"] %></title>
    <meta name="description" content="<%=Application["content"] %>">
    <meta name="keywords" content="<%=Application["key"] %>">
    <uc1:allLink runat="server" ID="allLink" />
    <script src="/js/article/ArticleWrite.js?<%=DateTime.Now.ToString("yyyyMMddHHmmssffff") %>"></script>
    <script src="/js/wangEditor.min.js?<%=DateTime.Now.ToString("yyyyMMddHHmmssffff") %>"></script>
    
</head>
<body>
    
    <div class="layui-row layui-col-space10 RowSpace margin0">
    <div class="layui-col-md7 layui-col-md-offset1 ">
    <div class="layui-panel">
    <div class="layui-row RowSpace">
        <div class="layui-col-md1 layui-col-xs2"><label class="text-left">标题：</label></div>
        <div class="layui-col-md11 layui-col-xs10"><input type="text" id="ArticleTitle" maxlength="100" value="测试一下" required lay-verify="required" placeholder="请输入标题" <%=editmsg!=null?"value=\""+editmsg[0].Title+"\"":""%> autocomplete="off" class="layui-input"></div>
    </div>
        <div class="layui-row RowSpace">
            <div id="articleContent">

                <%=(editmsg!=null)?editmsg[0].Content:""%>
            </div>
            <script>
            const E = window.wangEditor;
            const editor = new E('#articleContent');
                editorRen().create();
                  
            </script>
    </div>
</div>
</div><!--编辑器-->
    <div class="layui-col-md3">
    <div class="layui-row">
     <div class="layui-panel layui-clear layui-col-space10">
    <div class="layui-col-md2 layui-col-xs2"><label class="text-left">作者：</label></div>
     <div class="layui-col-md10 layui-col-xs10">
    <input type="text" class="layui-input" id="ArticleAuthor" placeholder="<%=Session["user_name"] %>" <%=(editmsg!=null)?"value=\""+editmsg[0].User_name+"\"":"" %> disabled>
    </div><!--作者框-->

     <div class="layui-col-md2 layui-col-xs2"><label class="text-left">时间：</label></div>
      <div class="layui-col-md10 layui-col-xs10">
     <input type="text" class="layui-input" id="ArticleDate" placeholder="请选择时间"  autocomplete="off" <%=(editmsg!=null)?"value=\""+editmsg[0].Date1+"\"":"" %> />
     <script>
     RenderDate('#ArticleDate','datetime',false,'yyyy-MM-ddTHH:mm:ss','1900-01-01','2099-12-31','click');
     </script>
     </div><!--时间选择-->

     <div class="layui-col-md2 layui-col-xs2"><label class="text-left">目录：</label></div>
      <div class="layui-col-md10 layui-col-xs10 layui-form">
     <select id="ArticleCatalog" lay-verify="" lay-search  autocomplete="off" >
        <option value="">请选择一个目录</option>
         <%
             List<catalog_Dao> catalog_list = catalog_Inc.Wrting();
             int catalog_list_count = catalog_list.Count;
             int i = 0;
             for (;i<catalog_list_count;i++) { 

             %>

         <option  value="<%=catalog_list[i].Id %>" <%=editCount != 0 ? Convert.ToInt32(editmsg[0].Catalog) == catalog_list[i].Id ? "selected":"":"" %> ><%=catalog_list[i].Name %></option>
         
         <%
             }
             %>
      </select>
     <script>
     RenderForm('select');
     </script>
     </div><!--分类选择-->

     <div class="layui-col-md3 layui-col-xs3"><label class="text-left">是否收费：</label></div>
       <div class="layui-col-md3 layui-col-xs3 layui-form">
        <input type="checkbox" id="isPay" lay-skin="switch" lay-filter="ispay" value="open" lay-text="开启|关闭" <%=(editmsg!=null)?editmsg[0].Charge.Length!=0?"checked":"":"" %>  autocomplete="off" >
        <script>
        onSwitch();
        </script>
      </div><!--收费开关选择-->
        <div class="layui-col-md6 layui-col-xs6 layui-form">
          <input type="text" class="layui-input <%=(editmsg!=null)?editmsg[0].Charge.Length!=0?"":"layui-hide":"layui-hide" %>" id="ArticlePrice" placeholder="请输入0或以上的整数" <%=(editmsg!=null)?"value=\""+editmsg[0].Price+"\"":"" %>  autocomplete="off" >
        </div><!--收费开关选择-->
    </div><!--面板标签-->
    </div><!--行1-->

    <div class="layui-row RowSpace <%=(editmsg!=null)?editmsg[0].Charge.Length!=0?"":"layui-hide":"layui-hide" %> " id="Article_Pay_window"><!--定义id用于隐藏-->
    <div class="layui-panel">
    <div class="layui-card">
      <div class="layui-card-header">收费内容</div>
      <div class="layui-card-body">
        <textarea id="ArticlePayContent" required lay-verify="required" placeholder="请输入收费内容" class="layui-textarea"   autocomplete="off" ><%=(editmsg!=null)?editmsg[0].Charge:"" %></textarea>
      </div>
    </div>
</div><!--面板结束-->
</div><!--行2-->

    <div class="layui-row RowSpace">
        <div class="layui-panel">
                <div class="layui-card">
                  <div class="layui-card-header">文章封面</div>
                  <div class="layui-card-body">
                    <div class="layui-row">
                    <div class="layui-col-md9">
                      <input type="text" id="ArticleImgUrl"  <%=(editmsg!=null)?"value=\""+editmsg[0].Img+"\"":"" %>  placeholder="请从文章内复制图片链接粘贴" autocomplete="off" class="layui-input">
                    </div><!--图片url-->
                      <div class="layui-col-md3">
                      <button type="button" class="layui-btn  layui-btn-primary layui-border-blue layui-btn-fluid" onclick="priview_Img()">预览</button>
                      </div>
                    </div><!--图片链接按钮-->
                  <div class="layui-row RowSpace">
                    <img src=" <%=(editmsg!=null)?"value=\""+editmsg[0].Img+"\"":"" %>" id="ArticleImgPriview" width="100%" height="200px">
                  </div><!--图片预览框-->
                  </div>
                </div>
        </div><!--面板结束-->
    </div><!--行3-->

    <div class="layui-row RowSpace">
    <div class="layui-panel">
        <div class="layui-card">
          <div class="layui-card-header">文章描述</div>
          <div class="layui-card-body">
            <textarea id="ArticleDescribe" required lay-verify="required" <%=(editmsg!=null)?"value=\""+editmsg[0].Describe+"\"":"" %> placeholder="请输入文章描述" class="layui-textarea"></textarea>
          </div>
        </div>
    </div><!--面板结束-->
    </div><!--行4-->

    <div class="layui-row RowSpace">
        <div class="layui-panel layui-col-space10 margin0 layui-clear">
            <div class="layui-col-md6">
                <%
                    if (editmsg!=null) { 
                    %>
                 <button type="button" class="layui-btn layui-btn-primary layui-border-blue layui-btn-fluid" onclick="Update_article(this)">更新文章</button>
                <%}else{%>
            <button type="button" class="layui-btn layui-btn-primary layui-border-blue layui-btn-fluid" onclick="Post_articles(this)">发布文章</button>
            <% }%>
        </div>
            <div class="layui-col-md6">
            <button type="button" class="layui-btn layui-btn-primary layui-border-blue layui-btn-fluid">保存文章</button>
        </div>
        </div><!--面板结束-->
        </div><!--行5-->
</div><!--侧边栏-->
</div><!--整个内容主体-->
</body>
</html>
